home *** CD-ROM | disk | FTP | other *** search
/ Amiga Plus Leser 15 / Amiga Plus Leser CD 15.iso / Tools / Development / PluginSRC_EvenMore / ProWrite2Text.e < prev    next >
Encoding:
Text File  |  2002-03-13  |  4.8 KB  |  195 lines

  1. /*
  2.    ProWrite2Text
  3.    EvenMore FileIO plugin
  4.    Author: Chris Perver
  5.    Copyright (c) 2001
  6. */
  7.  
  8.  
  9. OPT REG=5
  10.  
  11. LIBRARY 'prowrite2text.plugin',1,1,'ProWrite2Text 1.02' IS em_main, em_end, em_info, em_pluginid, em_begin, em_format
  12.  
  13. MODULE 'tools/ctype', '*epo'
  14.  
  15. DEF mem2, len2
  16.  
  17.  
  18. PROC em_isdatatype(memadr, lenadr)
  19.    DEF vers = FALSE
  20.    DEF w:PTR TO LONG
  21.  
  22.    -> Check for FORM header
  23.  
  24.    w := Long(memadr)
  25.    IF w = "FORM"
  26.      w := Long(memadr + 8)
  27.      IF w = "WORD" THEN vers := TRUE
  28.    ENDIF
  29. ENDPROC vers
  30.  
  31.  
  32. PROC em_parsedata(memadr, lenadr)
  33.   DEF count = 0, count2 = 0
  34.   DEF wrapping = 80, notdonewrapping = TRUE, currchar = 0
  35.   DEF notdone = TRUE
  36.   -> Allocate memory for file
  37. ->  IF (mem2 := New(lenadr + 1)) = NIL THEN RETURN -1
  38. ->  mem2[lenadr + 1] := "\n"                                                      -> Put safety LF at the end of mem
  39.   DEF w:PTR TO LONG
  40.   DEF ispara = FALSE, istabs = FALSE
  41.  
  42.   mem2 := memadr
  43.  
  44.    WHILE notdone AND (count < lenadr)
  45.  
  46.      w := Long(memadr + count)
  47.  
  48.          SELECT w
  49.            -> ???
  50.            CASE "PARA"
  51.              count := count + 4
  52.              mem2[count2++] := "\n"
  53.           ->   currchar := 0
  54.              ispara := TRUE
  55.            CASE "TABS"
  56.              count := count + 4
  57.              istabs := TRUE
  58.            CASE "FSCC"
  59.              count := count + 4
  60.            CASE "HEAD"
  61.              count := count + 4
  62.            CASE "FOOT"
  63.              count := count + 4
  64.            CASE "RMST"
  65.              count := count + 4
  66.            CASE "LMST"
  67.              count := count + 4
  68.            CASE "PCTS"
  69.              count := count + 4
  70.            CASE "BMAP"
  71.              count := count + 4
  72.            CASE "TEXT"
  73.          ->    count := count + 7
  74.              IF memadr[count + 7] <> $00
  75.                count := count + 8
  76.  
  77.                  IF istabs THEN mem2[count2++] := "\t"
  78.  
  79.                  istabs := FALSE
  80.  
  81.                  WHILE (memadr[count] <> $00)
  82.                    mem2[count2++] := memadr[count++]
  83.                    INC currchar
  84.                    IF currchar >= wrapping
  85.                      notdonewrapping := TRUE
  86.                      WHILE notdonewrapping
  87.                        SELECT 256 OF memadr[count]
  88.                          DEFAULT
  89.                            IF isspace(memadr[count]) = FALSE
  90.                              DEC count
  91.                              DEC count2
  92.                            ELSE
  93.                              notdonewrapping := FALSE
  94.                            ENDIF
  95.                        ENDSELECT
  96.                      ENDWHILE
  97.                      INC count
  98.  
  99.                      currchar := 0
  100.                      memadr[count2++] := "\n"
  101.                      IF istabs THEN mem2[count2++] := "\t"
  102.                    ENDIF
  103.                  ENDWHILE
  104.  
  105.                  -> STRIP TRAILING COMMANDS
  106.  
  107.                  w := Long(memadr + count - 4)
  108.                  SELECT w
  109.                    CASE "TEXT"
  110.                     count2 := count2 - 4
  111.                     count := count - 4
  112.            ->         mem2[count2++] := "\n"
  113.            ->         currchar := 0
  114.                    CASE "PARA"
  115.                     count2 := count2 - 4
  116.                     count := count - 4
  117.              ->       mem2[count2++] := "\n"
  118.              ->       currchar := 0
  119.              ->       ispara := FALSE
  120.                  ->   istabs := FALSE
  121.                    CASE "TABS"
  122.                     count2 := count2 - 4
  123.                     count := count - 4
  124.            ->         istabs := FALSE
  125.                    CASE "FSCC"
  126.                     count2 := count2 - 4
  127.                    CASE "HEAD"
  128.                     count2 := count2 - 4
  129.                    CASE "FOOT"
  130.                     count2 := count2 - 4
  131.                    CASE "PTCS"
  132.                      count2 := count2 - 4
  133.                    CASE "BMAP"
  134.                      count2 := count2 - 4
  135.                  ENDSELECT
  136.               ->   INC count
  137.  
  138.                  mem2[count2++] := "\n"
  139.                  currchar := 0
  140.              ELSE
  141.                mem2[count2++] := "\n"
  142.                currchar := 0
  143.                INC count
  144.              ENDIF
  145.            DEFAULT
  146.              INC count
  147.          ENDSELECT
  148.  
  149. ->       DEFAULT
  150.  
  151. ->         INC count
  152. ->     ENDSELECT
  153.  
  154.    ENDWHILE
  155.  
  156.  
  157.   mem2[count2] := "\n"
  158.  
  159.  -> IF memadr
  160.  ->   Dispose(memadr); memadr := NIL
  161.  -> ENDIF
  162. ENDPROC mem2, count2
  163. -><
  164.  
  165. -> *** STANDARD PROCS FOR PLUGINS
  166.  
  167.  
  168. PROC em_main(epo:PTR TO em_pluginobj)
  169.   mem2, len2 := em_parsedata(epo.buffer, epo.length)
  170.   epo.buffer := mem2
  171.   epo.length := len2
  172.   RETURN TRUE
  173. ENDPROC
  174.  
  175. PROC em_begin(epo:PTR TO em_pluginobj)
  176.   DEF vers
  177.   vers := em_isdatatype(epo.buffer, epo.length)
  178.   IF vers
  179.     RETURN TRUE
  180.   ELSE
  181.     RETURN FALSE
  182.   ENDIF
  183.  
  184. ENDPROC
  185.  
  186. PROC em_end()      IS EMPTY
  187.  
  188. PROC em_info()     IS 'ProWrite2Text 1.02'
  189.  
  190. PROC em_pluginid() IS "FILE"
  191.  
  192. PROC em_format()   IS 'ProWrite'
  193.  
  194. PROC main()        IS EMPTY
  195.